package cn.otrue.patienthealthmanager.adapter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.bean.FreeAskModel;
import cn.otrue.patienthealthmanager.utils.CommonUtil;

public class MessageFreeASKAdapter extends BaseAdapter {
	List<FreeAskModel> FreeAsk;
	LayoutInflater inflater;
	Context context;
	private TextView tv_centermessage_datatips;
	private TextView tv_catt_dialogRight;
	private TextView tv_catt_dialogLeft;

	public MessageFreeASKAdapter(Context context, List<FreeAskModel> FreeAsk) {
		this.FreeAsk = FreeAsk;
		inflater = LayoutInflater.from(context);
		this.context = context;
	}

	@Override
	public int getCount() {
		return FreeAsk != null ? FreeAsk.size() : 0;
	}

	@Override
	public Object getItem(int arg0) {
		return FreeAsk.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		HolderView holder;
		if (convertView == null) {
			holder = new HolderView();
			convertView = inflater.inflate(R.layout.layout_centermessage_item,
					null);
			holder.iv_center_message_item = (ImageView) convertView.findViewById(R.id.iv_center_message_item);
			holder.tv_centermessage_title = (TextView) convertView.findViewById(R.id.tv_centermessage_title);
			holder.tv_centermessage_describe = (TextView) convertView.findViewById(R.id.tv_centermessage_describe);
			holder.tv_centermessage_time = (TextView) convertView.findViewById(R.id.tv_centermessage_time);
			convertView.setTag(holder);
		} else {
			holder = (HolderView) convertView.getTag();
		}
		holder.tv_centermessage_title.setText(CommonUtil.getName(null, FreeAsk.get(arg0).d_realname, null)+"向"+CommonUtil.getName(null, FreeAsk.get(arg0).p_realname, FreeAsk.get(arg0).p_useraccount)+"提问：“"+FreeAsk.get(arg0).content+"”的问题");
		String time =FreeAsk.get(arg0).createtime;
		// if((time==null)||("".equals(""))){
		// time="";
		// }else{
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-d H:m:s");
		try {
			Date date = format.parse(time);
			time = format.format(date);
		} catch (ParseException e) {
			e.printStackTrace();
			time = "";
		}
		holder.tv_centermessage_time.setText(time);
		return convertView;
	}

	public class HolderView {
		ImageView iv_center_message_item;
		TextView tv_centermessage_title;
		TextView tv_centermessage_describe;
		TextView tv_centermessage_time;
	}
}
